﻿using Autofac;
using GBlog.Core.Data.Default;
using GBlog.Core.Data;
using GBlog.Core.Service;
using System.Web;
using GBlog.Core.Service.Default;
using GBlog.Core.Entities;

namespace GBlog.Core
{
    internal sealed class GRegister : IGRegister
    {
        public void RegisterServices(ContainerBuilder builder)
        {
            builder.RegisterType<SystemService>().As<ISystemService>().InstancePerLifetimeScope();
            builder.RegisterType<GContext>().As<IDbContext>().InstancePerDependency();
            builder.RegisterType<UserService>().As<IUserService>().InstancePerDependency();
            builder.RegisterType<ConfigService>().As<IConfigService>().InstancePerLifetimeScope().WithParameter("FilePath", HttpContext.Current.Server.MapPath("~/App_Data"));
            builder.RegisterType<ThemeService>().As<IThemeService>().InstancePerLifetimeScope();
            builder.RegisterType<ErrorService>().As<IErrorService>().InstancePerLifetimeScope();
            builder.RegisterType<Services>().As<IServices>().InstancePerLifetimeScope();
        }

        public void Seed(IDbContext context)
        {
            User byfabs = new User();
            byfabs.Email = "ahmetturk93@gmail.com";
            byfabs.Password = "13487171a";
            byfabs.Seo = "byfabs";
            byfabs.Username = "ByFabs";
            context.Set<User>().Add(byfabs);
        }
    }
}